package com.ricky;

import com.intellij.openapi.project.Project;
import com.intellij.openapi.ui.Messages;

import java.io.IOException;

/**
 * Created by baiguantao on 2017/12/20.
 */
public class FileUtil {
    public static void openDir(String realPath,Project project){
        if (realPath!="") {
            String dir=realPath.substring(0,realPath.lastIndexOf("/"));
            System.out.println("dir:"+dir);
            try {
                String osName=System.getProperty("os.name").toLowerCase();
                if (osName.contains("windows")) {
                    Runtime.getRuntime().exec("cmd /c start "+dir);
                }else
                if (osName.contains("linux")) {
                    Runtime.getRuntime().exec("cd "+dir);
                }else
                if (osName.contains("mac")) {
                    Runtime.getRuntime().exec("cd "+dir);
                }else {
                    Messages.showWarningDialog(project,"插件暂不支持该操作系统","结果");
                }

            } catch (IOException e) {
                e.printStackTrace();
                Messages.showWarningDialog(project,"插件错误,请联系作者","结果");
            }
        }
    }
}
